const request = require('request')
const { Writetext } = require("./Error")
const Host = "http://47.103.96.35:8091"
const Token = ""
function POST (url, data) {
    return new Promise(function (resolve, reject) {
        request({
            url: Host + url,
            method: "POST",
            json: true,
            headers: {
                "Authorization": Token,
                "content-type": "application/json",
            },
            body: data
        }, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                resolve(body)
            } else {
                reject(error)
                Writetext(error)
            }
        })
    })
}
function GET (url, data) {
    return new Promise(function (resolve, reject) {
        request({
            url: Host + url,
            method: "GET",
            json: true,
            headers: {
                "Authorization": Token,
                "content-type": "application/json",
            },
            body: JSON.stringify(data)
        }, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                resolve(body)
            } else {
                reject(error)
                Writetext(error)
            }
        })
    })
}
function PUT (url, data) {
    return new Promise(function (resolve, reject) {
        request({
            url: Host + url,
            method: "PUT",
            json: true,
            headers: {
                "Authorization": Token,
                "content-type": "application/json",
            },
            body: JSON.stringify(data)
        }, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                resolve(body)
            } else {
                reject(error)
                Writetext(error)
            }
        })
    })
}
module.exports = {
    POST,
    GET,
    PUT
}